import configUrls from "../urls/aa";
import { get, post, $setToken } from "../httpRequest";
import { message } from 'ant-design-vue';

export const $doLogin = async (params) => {
    let ret = post(configUrls.doLogin, params).then((result) => {
        let { code, msg, data } = result;
        if (result.code == "00001") {
            sessionStorage.setItem('token', data.token);
            $setToken(data.token);
            if (params.remember) {
                localStorage.setItem("aa", JSON.stringify(params));
            }
            message.success(msg);
            return true;
        } else {
            message.error(msg);
            return false;
        }
    });
    return ret;
}

export const $getMineMenus = async(params) =>{
    return post(configUrls.getMineMenus, params);
}

export const $doLogout = async (params) => {
    let ret = post(configUrls.logout, params).then((result) => {
        sessionStorage.clear();
        localStorage.clear();
        let { code, msg, data } = result;
        if (result.code == "00001") {
            message.success(msg);
        } else {
            message.error(msg);
        }
        return true;
    });
    return ret;
}

